home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / modes / whitespace-mode.el.z / whitespace-mode.el
Encoding:
Text File  |  1998-05-21  |  18.8 KB  |  587 lines

  1. ;;; whitespace-mode.el -- minor mode for making whitespace visible
  2.  
  3. ;; Copyright (C) 1994, 1995, 1996 Heiko Muenkel
  4.  
  5. ;; Author: Heiko Muenkel <muenkel@tnt.uni-hannover.de>
  6. ;; Keywords: modes, extensions
  7.  
  8. ;; This file is part of XEmacs.
  9.  
  10. ;;  XEmacs is free software; you can redistribute it and/or modify it
  11. ;;  under the terms of the GNU General Public License as published by
  12. ;;  the Free Software Foundation; either version 2, or (at your
  13. ;;  option) any later version.
  14.  
  15. ;;  XEmacs is distributed in the hope that it will be useful, but
  16. ;;  WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18. ;;  General Public License for more details.
  19.  
  20. ;;  You should have received a copy of the GNU General Public License
  21. ;;  along with XEmacs; if not, write to the Free Software
  22. ;;  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23. ;; 02111-1307, USA.
  24.  
  25. ;;; Synched up with: FSF 19.34.
  26.  
  27. ;;; Commentary:
  28.  
  29. ;; $Id: whitespace-mode.el,v 1.18 1996/08/17 15:40:42 muenkel Exp $
  30. ;; Description:
  31. ;;
  32. ;;    This is a minor mode, which highlights whitespaces (blanks and
  33. ;;    tabs) with different faces, so that it is easier to
  34. ;;    distinguish between them.  
  35. ;;    Toggle the mode with: M-x whitespace-mode 
  36. ;;     or with: M-x whitespace-incremental-mode
  37. ;;    The second one should be used in big files.
  38. ;;
  39. ;;    If you want to know how the whitespaces are highlighted then
  40. ;;    type: M-x whitespace-show-faces
  41. ;;
  42. ;;    There are 2 hook variables `whitespace-incremental-mode-hook'
  43. ;;    and `whitespace-mode-hook' to customize the mode.
  44. ;;
  45. ;;    Look at the variable `whitespace-chars', if you only want to
  46. ;;    highlight tabs or blanks and not both.
  47. ;;
  48. ;;    Set `whitespace-install-toolbar-icon' to t, if you want a
  49. ;;    toolbar icon for this mode.
  50. ;;
  51. ;;    Set `whitespace-install-submenu' to t, if you want a submenu
  52. ;;     for this mode. Sorry, at the moment there is no menu for the
  53. ;;    Emacs 19. 
  54. ;;
  55. ;;    Thanks to Mike Scheidler for the toolbar icon code.
  56. ;; 
  57. ;; Installation:
  58. ;;   
  59. ;;     Put the files whitespace-mode.el and adapt.el in one of your
  60. ;;     load-path directories and the following lines (without the
  61. ;;     comment signs) in your .emacs (adapt.el is already in the
  62. ;;    XEmacs 19.12).
  63. ;;
  64. ;;     (autoload 'whitespace-mode "whitespace-mode" 
  65. ;;       "Toggle whitespace mode.
  66. ;;    With arg, turn whitespace mode on iff arg is positive.
  67. ;;    In whitespace mode the different whitespaces (tab, blank return)
  68. ;;    are highlighted with different faces. The faces are:
  69. ;;    `whitespace-blank-face', `whitespace-tab-face' and 
  70. ;;    `whitespace-return-face'."
  71. ;;    t)
  72. ;;
  73. ;;     (autoload 'whitespace-incremental-mode "whitespace-mode" 
  74. ;;      "Toggle whitespace incremental mode.
  75. ;;     With arg, turn whitespace incremental mode on iff arg is positive.
  76. ;;    In whitespace incremental mode the different whitespaces (tab and 
  77. ;;    blank) are highlighted with different faces. The faces are:
  78. ;;    `whitespace-blank-face' and `whitespace-tab-face'.
  79. ;;    Use the command `whitespace-show-faces' to show their values.
  80. ;;    In this mode only these tabs and blanks are highlighted, which are in 
  81. ;;    the region from (point) - (window-heigh) to (point) + (window-heigh)."
  82.  
  83. ;;; Code:
  84.  
  85. (provide 'whitespace-mode)
  86. (require 'adapt)
  87.  
  88. ;;; variables:
  89.  
  90. (defgroup whitespace nil
  91.   "Minor mode for making whitespace visible"
  92.   :group 'outlines
  93.   :group 'matching)
  94.  
  95.  
  96. (defcustom whitespace-mode nil
  97.   "Non-nil, if the `whitespace-mode' is active."
  98.   :type 'boolean
  99.   :set (lambda (symbol value)
  100.      (whitespace-mode (or value 0)))
  101.   :require 'whitespace-mode
  102.   :initialize 'custom-initialize-default
  103.   :group 'whitespace)
  104.  
  105. (make-variable-buffer-local 'whitespace-mode)
  106.  
  107. (defcustom whitespace-chars 'tabs-and-blanks
  108.   "*Determines, which whitespaces are highlighted.
  109. Valid values are:
  110. 'tabs-and-blanks => tabs and blanks are highlighted;
  111. 'tabs            => only tabs are highlighted;
  112. 'blanks          => only blanks are highlighted;.
  113.  
  114. Changing this variable during the whitespace-*-mode is active could lead
  115. to wrong highlighted whitespaces."
  116.   :type '(radio (const tabs-and-blanks)
  117.         (const tabs)
  118.         (const blanks))
  119.   :group 'whitespace)
  120.  
  121. (make-variable-buffer-local 'whitespace-chars)
  122.  
  123. (defcustom whitespace-mode-hook nil
  124.   "*Run after the `whitespace-mode' is switched on."
  125.   :type 'hook
  126.   :group 'whitespace)
  127.  
  128. (defcustom whitespace-incremental-mode-hook nil
  129.   "*Run after the `whitespace-incremental-mode' is switched on."
  130.   :type 'hook
  131.   :group 'whitespace)
  132.  
  133.  
  134. (if (adapt-xemacsp)
  135. (progn
  136.  
  137. (defcustom whitespace-install-toolbar-icon nil
  138.   "Set it to t, if a toolbar icon should be installed during loading this file.
  139. The icon calls the function 'whitespace-toolbar-function'."
  140.   :type 'boolean
  141.   :group 'whitespace)
  142.  
  143. (defcustom whitespace-install-submenu nil
  144.   "Set it to t, if a submenu should be installed during loading this file."
  145.   :type 'boolean
  146.   :group 'whitespace)
  147.  
  148. ))
  149.  
  150.  
  151. (defcustom whitespace-toolbar-function 'whitespace-incremental-mode
  152.   "*The toolbar icon for the whitespace mode calls this function.
  153. Valid values are: 'whitespace--mode and 'whitespace-incremental-mode."
  154.   :type 'function
  155.   :group 'whitespace)
  156.  
  157. (defcustom whitespace-blank-and-tab-search-string "\\( \\)\\|\\(\t\\)"
  158.   "The regexp used to search for tabs and blanks."
  159.   :type 'regexp
  160.   :group 'whitespace)
  161.  
  162. (defcustom whitespace-tab-search-string "\t"
  163.   "The search string used to find tabs."
  164.   :type 'string
  165.   :group 'whitespace)
  166.  
  167. (defcustom whitespace-blank-search-string " "
  168.   "The search string used to find blanks."
  169.   :type 'string
  170.   :group 'whitespace)
  171.  
  172. (defface whitespace-blank-face
  173.   '((t
  174.      (:background "LightBlue1")))
  175.   "Face to show blanks with"
  176.   :group 'whitespace)
  177.  
  178. (defface whitespace-tab-face
  179.   '((t
  180.      (:background "yellow" :underline t)))
  181.   "Face to show TABs with"
  182.   :group 'whitespace)
  183.  
  184. (defun whitespace-show-faces ()
  185.   "Shows the faces used by the `whitespace-mode'."
  186.   (interactive)
  187.   (save-excursion
  188.     (let ((actual-buffer-name (buffer-name (current-buffer)))
  189.       (actual-whitespace-chars whitespace-chars)
  190.       (whitespace-mode-active (or whitespace-mode 
  191.                       whitespace-incremental-mode))
  192.       (buffer (get-buffer-create "*Help*")))
  193.       (set-buffer buffer)
  194.       (setq whitespace-chars actual-whitespace-chars)
  195.       (delete-region (point-min) (point-max))
  196.       (insert "In the whitespace minor mode\n"
  197.           " this \" ")
  198.       (whitespace-highlight-region (1- (point)) (point))
  199.       (insert "\" is a blank, highlighted with `whitespace-blank-face' and\n"
  200.           " this \"\t")
  201.       (whitespace-highlight-region (1- (point)) (point))
  202.       (insert "\" is a tab,  highlighted with `whitespace-tab-face'.")
  203.       
  204.       (newline 2)
  205.       (if (eq whitespace-chars 'blanks)
  206.       (insert 
  207.        "The highlighting of tabs is switched off.\n")
  208.     (if (eq whitespace-chars 'tabs)
  209.         (insert
  210.          "The highlighting of blanks is switched off.\n")))
  211.       (newline)
  212.       (if whitespace-mode-active
  213.       (insert "A whitespace minor mode is active in the buffer\n  "
  214.           actual-buffer-name
  215.           ".\n")
  216.     (insert "No whitespace minor mode is active in the buffer\n  "
  217.         actual-buffer-name
  218.         ".\n"))
  219.       (show-temp-buffer-in-current-frame buffer)
  220.       )))
  221.  
  222. ;;;
  223. (defun whitespace-highlight-chars-in-region (char-string from to face)
  224.   "Highlights the CHAR-STRING in the region from FROM to TO with the FACE."
  225.   (while (search-forward char-string end t)
  226.     (let ((extent))
  227.       (cond ((match-beginning 0)
  228.          (setq extent (make-extent (match-beginning 0) (match-end 0)))
  229.          (set-extent-face extent face)
  230.          ))
  231.       (set-extent-property extent 'start-open t)
  232.       (set-extent-property extent 'end-open t)
  233.       )))
  234.  
  235. (defun whitespace-highlight-region (from to)
  236.   "Highlights the whitespaces in the region from FROM to TO."
  237.   (let ((start (min from to))
  238.     (end (max from to)))
  239.     (save-excursion
  240.       ;;    (message "Highlighting tabs and blanks...")
  241.       (goto-char start)
  242.       (cond ((eq whitespace-chars 'tabs-and-blanks)
  243.          (while (search-forward-regexp 
  244.              whitespace-blank-and-tab-search-string end t)
  245.            (let ((extent))
  246.          (cond ((match-beginning 1) ; blanks ?
  247.             (setq extent (make-extent (match-beginning 1) 
  248.                           (match-end 1)))
  249.             (set-extent-face extent 'whitespace-blank-face)
  250.             )
  251.                ((match-beginning 2) ; tabs ?
  252.             (setq extent (make-extent (match-beginning 2) 
  253.                           (match-end 2)))
  254.             (set-extent-face extent 'whitespace-tab-face)
  255.             )
  256.                )
  257.          (set-extent-property extent 'start-open t)
  258.          (set-extent-property extent 'end-open t)
  259.          )))
  260.         ((eq whitespace-chars 'tabs)
  261.          (whitespace-highlight-chars-in-region whitespace-tab-search-string 
  262.                            from 
  263.                            to
  264.                            'whitespace-tab-face))
  265.         ((eq whitespace-chars 'blanks)
  266.          (whitespace-highlight-chars-in-region 
  267.           whitespace-blank-search-string 
  268.           from 
  269.           to
  270.           'whitespace-blank-face))
  271.         (t (error "ERROR: Bad value of whitespace-highlight-char")))
  272.       ;;    (message "")
  273.       )))
  274.  
  275. (defun whitespace-highlight-buffer ()
  276.   "Highlights the whitespaces in the current buffer."
  277.   (whitespace-highlight-region (point-min) (point-max))
  278. )
  279.  
  280. (defsubst whitespace-find-next-highlighted-region (from to)
  281.   "Returns nil or the next highlighted region."
  282.   (map-extents '(lambda (extent dummy)
  283.          (if (extent-property extent 'whitespace-highlighted-region)
  284.              extent))
  285.            nil
  286.            from
  287.            to))
  288.  
  289. (defun whitespace-incremental-highlight (from to)
  290.   "Highligthts the region from FROM to TO incremental."
  291.   (save-excursion
  292.     (goto-char from)
  293.     (let ((extent (extent-at (point) nil 'whitespace-highlighted-region))
  294.       (next-extent nil)
  295.       (start nil))
  296.       (while (< (point) to)
  297.     (if extent
  298.         (goto-char (extent-end-position extent)))
  299.     (if (< (point) to)
  300.         (progn
  301.           (setq start (point))
  302.           
  303.           (setq next-extent (whitespace-find-next-highlighted-region 
  304.                  start
  305.                  to))
  306.           (if extent
  307.           (if next-extent
  308.               (progn
  309.             (set-extent-endpoints extent 
  310.                           (extent-start-position extent)
  311.                           (extent-end-position next-extent)
  312.                           )
  313.             (whitespace-highlight-region start
  314.                              (1-
  315.                               (extent-start-position
  316.                                next-extent)))
  317.             (delete-extent next-extent))
  318.             (set-extent-endpoints extent
  319.                       (extent-start-position extent)
  320.                       to)
  321.             (whitespace-highlight-region start to))
  322.         (if next-extent
  323.             (progn
  324.               (setq extent next-extent)
  325.               (whitespace-highlight-region start 
  326.                            (1- (extent-start-position
  327.                             next-extent)))
  328.               (set-extent-endpoints extent
  329.                         start
  330.                         (extent-end-position next-extent)))
  331.           (setq extent (make-extent start to))
  332.           (set-extent-property extent 'whitespace-highlighted-region t)
  333.           (whitespace-highlight-region start to)))
  334.           ))))))
  335.  
  336.  
  337. (defun whitespace-highlight-window ()
  338.   "Highlights the whitespaces in the current window."
  339.   (whitespace-incremental-highlight (save-excursion
  340.                       (forward-line (- (window-height)))
  341.                       (point))
  342.                     (save-excursion
  343.                       (forward-line (window-height))
  344.                       (point))))
  345.  
  346. (defun whitespace-dehighlight-region (start end)
  347.   "Dehighlights the whitespaces in the region from START to END."
  348.   (map-extents '(lambda (extent dummy)
  349.           (if (or (eq (extent-face extent) 'whitespace-blank-face)
  350.               (eq (extent-face extent) 'whitespace-tab-face)
  351.               (extent-property extent 
  352.                        'whitespace-highlighted-region))
  353.               (progn
  354.             (delete-extent extent)
  355.             nil)))
  356.            nil
  357.            start
  358.            end
  359.            )
  360.   )
  361.  
  362. (defun whitespace-dehighlight-buffer ()
  363.   "Dehighlights the whitespaces in the current buffer."
  364.   (whitespace-dehighlight-region (point-min) (point-max))
  365.   )
  366.  
  367. (defun whitespace-highlight-after-change-function (beg end old-len)
  368.   "Called, when any modification is made to buffer text.  Highlights
  369. the whitespaces (blanks and tabs) in the region from BEG to
  370. END. OLD-LEN isn't used, but provided from the after-change hook."
  371.   (if (or (eq beg end)
  372.       (null whitespace-mode))
  373.       nil
  374.     (whitespace-dehighlight-region beg end)
  375.     (whitespace-highlight-region beg end)))
  376.  
  377. (defun whitespace-mode (&optional arg)
  378.   "Toggle whitespace mode.
  379. With arg, turn whitespace mode on iff arg is positive.
  380. In whitespace mode the different whitespaces (tab and blank)
  381. are highlighted with different faces. The faces are:
  382. `whitespace-blank-face' and `whitespace-tab-face'.
  383. Use the command `whitespace-show-faces' to show their values."
  384.   (interactive "P")
  385.   (setq whitespace-mode
  386.     (if (null arg) (not whitespace-mode)
  387.       (> (prefix-numeric-value arg) 0)))
  388.   (if (and whitespace-mode whitespace-incremental-mode)
  389.       (progn
  390.     (whitespace-incremental-highlight (point-min) (point-max))
  391.     (setq whitespace-incremental-mode nil)
  392.     (remove-hook 'post-command-hook 'whitespace-highlight-window)
  393.     (run-hooks 'whitespace-mode-hook)
  394.     )
  395.     (setq whitespace-incremental-mode nil)
  396.     (remove-hook 'post-command-hook 'whitespace-highlight-window)
  397.     (redraw-modeline) ;(force-mode-line-update)
  398.     (if whitespace-mode
  399.     (progn
  400.       (whitespace-highlight-buffer)
  401.       (make-local-variable 'after-change-functions)
  402.       (add-hook 'after-change-functions 
  403.             'whitespace-highlight-after-change-function)
  404.       (run-hooks 'whitespace-mode-hook))
  405.       (whitespace-dehighlight-buffer)
  406.       (remove-hook 'after-change-functions 
  407.            'whitespace-highlight-after-change-function)
  408.       (remove-hook 'post-command-hook 'whitespace-highlight-window)
  409.       )))
  410.  
  411. (defvar whitespace-incremental-mode nil
  412.   "Non-nil, if the `whitespace-incremental-mode' is active.")
  413.  
  414. (make-variable-buffer-local 'whitespace-incremental-mode)
  415.  
  416. (defun whitespace-incremental-mode (&optional arg)
  417.   "Toggle whitespace incremental mode.
  418. With arg, turn whitespace incremental mode on iff arg is positive.
  419. In whitespace incremental mode the different whitespaces (tab and blank)
  420. are highlighted with different faces. The faces are:
  421. `whitespace-blank-face' and `whitespace-tab-face'.
  422. Use the command `whitespace-show-faces' to show their values.
  423. In this mode only these tabs and blanks are highlighted, which are in 
  424. the region from (point) - (window-heigh) to (point) + (window-heigh)."
  425.   (interactive "P")
  426.   (setq whitespace-incremental-mode
  427.     (if (null arg) (not whitespace-incremental-mode)
  428.       (> (prefix-numeric-value arg) 0)))
  429.   (if (and whitespace-mode whitespace-incremental-mode)
  430.     (set-extent-property (make-extent (point-min) (point-max))
  431.                  'whitespace-highlighted-region
  432.                  t))
  433.   (setq whitespace-mode nil)
  434.   (redraw-modeline) ;(force-mode-line-update)
  435.   ;(set-buffer-modified-p (buffer-modified-p)) ;No-op, but updates mode line.
  436.   (if whitespace-incremental-mode
  437.       (progn
  438.     (whitespace-highlight-window)
  439.     (make-local-variable 'post-command-hook)
  440.     (add-hook 'post-command-hook 'whitespace-highlight-window)
  441.     (make-local-variable 'after-change-functions)
  442.     (add-hook 'after-change-functions 
  443.           'whitespace-highlight-after-change-function)
  444.     (run-hooks 'whitespace-incremental-mode-hook))
  445.     (whitespace-dehighlight-buffer)
  446.     (remove-hook 'after-change-functions 
  447.          'whitespace-highlight-after-change-function)
  448.     (remove-hook 'post-command-hook 'whitespace-highlight-window)
  449.     ))
  450.  
  451.  
  452. ;;; Add whitespace-mode and whitespace-incremental-mode to the minor-mode-alist
  453.  
  454. (or (assq 'whitespace-mode minor-mode-alist)
  455.     (setq minor-mode-alist
  456.       (cons '(whitespace-mode " WSP") minor-mode-alist)))
  457.  
  458. (or (assq 'whitespace-incremental-mode minor-mode-alist)
  459.     (setq minor-mode-alist
  460.       (cons '(whitespace-incremental-mode " WSPI") minor-mode-alist)))
  461.  
  462.  
  463. ;;; Menu for the whitespace mode
  464.  
  465. (defun whitespace-set-whitespace-chars (new-whitespace-chars)
  466.   "Sets the variable `whitespace-chars' and activates the change."
  467.   (interactive (list (read (completing-read "Whitespaces to highlight: "
  468.                         '(("tabs-and-blanks")
  469.                           ("tabs")
  470.                           ("blanks"))
  471.                         nil
  472.                         t
  473.                         (symbol-name 'whitespace-chars)))))
  474.   (if (eq whitespace-chars new-whitespace-chars)
  475.       nil ; nothing to do
  476.     (setq whitespace-chars new-whitespace-chars)
  477.     (setq-default whitespace-chars new-whitespace-chars)
  478.     (cond (whitespace-mode (whitespace-mode) 
  479.                (whitespace-mode))
  480.       (whitespace-incremental-mode (whitespace-incremental-mode)
  481.                        (whitespace-incremental-mode))
  482.       )))
  483.  
  484. (defvar whitespace-menu nil
  485.   "A menu for the whitespace minor mode.")
  486.   
  487. (setq whitespace-menu
  488.       '("Whitespace Menu"
  489.     ["Highlight Whitespaces" 
  490.      whitespace-mode 
  491.      :style toggle 
  492.      :selected whitespace-mode]
  493.     ["Incremental Highlighting"
  494.      whitespace-incremental-mode
  495.      :style toggle
  496.      :selected whitespace-incremental-mode
  497.      ]
  498.     "---"
  499.     ["Show Whitespace Faces" whitespace-show-faces t]
  500.     "---"
  501.     ["Highlight Tabs & Blanks" 
  502.      (whitespace-set-whitespace-chars 'tabs-and-blanks)
  503.      :style radio
  504.      :selected (eq whitespace-chars 'tabs-and-blanks)]
  505.     ["Highlight Only Tabs"
  506.      (whitespace-set-whitespace-chars 'tabs)
  507.      :style radio
  508.      :selected (eq whitespace-chars 'tabs)]
  509.     ["Highlight Only Blanks"
  510.      (whitespace-set-whitespace-chars 'blanks)
  511.      :style radio
  512.      :selected (eq whitespace-chars 'blanks)]
  513.     ))
  514.  
  515. (if (and (boundp 'whitespace-install-submenu) whitespace-install-submenu)
  516.     (add-submenu '("Apps") whitespace-menu))
  517.  
  518. ;;; Toolbar icon for the XEmacs
  519.  
  520. (if (featurep 'toolbar)
  521.  
  522. (defvar toolbar-wspace-icon
  523.   (toolbar-make-button-list
  524.    "/* XPM */
  525. static char * whitespace[] = {
  526. \"28 28 4 1\",
  527. \"     c Gray75 s backgroundToolBarColor\",
  528. \".    c black\",
  529. \"X    c Gray60\",
  530. \"o    c white\",
  531. \"                            \",
  532. \"                            \",
  533. \"                            \",
  534. \"                            \",
  535. \"         ..      .          \",
  536. \"       XXX.XXXXXX   .       \",
  537. \"       Xoo.oooooXX  .       \",
  538. \" .. .. ..o.o..oo..X...  ..  \",
  539. \"  .  . X.o..o.ooX. X.  .  . \",
  540. \"  .  . .oo.oo.ooX.XX.  .... \",
  541. \"   ... .oo.oo.ooo.oo.  .    \",
  542. \"   .  .Xoo.oo.ooo.oo.  .  . \",
  543. \"   .  .Xo...o..o...o..  ..  \",
  544. \"       XooooooooooooX       \",
  545. \"       XooooooooooooX       \",
  546. \" .... ....ooo...ooo...  ..  \",
  547. \" .  .  .oo.o.oo.oo.oX. .  . \",
  548. \"  .    .oo.ooo..oo.oX  .... \",
  549. \"   ..  .oo.o..o.oo.oX  .    \",
  550. \" .  .  .oo.o.oo.oo.oX. .  . \",
  551. \" ....  ...oo.....oo..   ..  \",
  552. \"       .ooooooooooooX       \",
  553. \"       .XXXXXXXXXXXXX       \",
  554. \"       .                    \",
  555. \"      ...                   \",
  556. \"                            \",
  557. \"                            \",
  558. \"                            \"
  559. };")
  560.   "A whitespace icon.")
  561. )
  562.  
  563. (defun whitespace-toolbar-function ()
  564.   "Calls the function determined by `whitespace-toolbar-function'."
  565.   (interactive)
  566.   (call-interactively whitespace-toolbar-function))
  567.  
  568. (if (and (adapt-xemacsp)
  569.      whitespace-install-toolbar-icon
  570.      (featurep 'toolbar)
  571.      (eq (device-type (selected-device)) 'x))
  572.     (let ((tb (mapcar #'(lambda (e)
  573.               (elt e 1)) (specifier-instance default-toolbar))))
  574.       (and (not (member 'whitespace-toolbar-function tb))
  575.        (toolbar-add-item
  576.         [toolbar-wspace-icon whitespace-toolbar-function
  577.                  t "Toggle whitespace mode"]
  578.         (let ((n (or
  579.               (position 'toolbar-replace tb)
  580.               (position 'toolbar-undo tb)
  581.               (position 'toolbar-paste tb)
  582.               (position 'toolbar-copy tb)
  583.               (position 'toolbar-cut tb))))
  584.           (if n (1+ n) (length tb)))))))
  585.  
  586. ;;; whitespace-mode.el ends here
  587.